package com.feituan.core.persistence.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.feituan.core.persistence.mapper.OrderMapper;
import com.feituan.core.persistence.service.IOrderService;
import com.feituan.core.pojo.entity.Order;
import com.feituan.core.pojo.request.OrderPageReq;
import com.feituan.core.pojo.response.page.PageData;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xiaohu
 * @since 2024-05-09
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements IOrderService {
    @Override
    public PageData<Order> queryPage(OrderPageReq request) {
        Page<Order> page = this.lambdaQuery()
                .eq(!StringUtils.isEmpty(request.getOrderSn()),Order::getOrderSn,request.getOrderSn())
                .eq(request.getUserId() != null,Order::getUserId,request.getUserId())
                .eq(request.getType() != null,Order::getType,request.getType())
                .orderByDesc(Order::getId)
                .page(new Page<>(request.getPage(), request.getLimit()));
        return PageData.build(page.getCurrent(), page.getTotal(), page.getRecords());
    }

    @Override
    public Order getBySn(String sn) {
        return this.lambdaQuery().eq(Order::getOrderSn,sn).one();
    }

    @Override
    public List<Order> findByUser(Long userId,Integer type, Long lastId,Integer orderStatus) {
        return this.getBaseMapper().findByUser(userId,type,lastId,orderStatus);
    }
}
